﻿<link href="~/Themes/RongJi/Style/base/css/account.css" rel="stylesheet">
@model RiderShop.Mobile.ServiceEntity.MyAccount.UserShipingAddressExtend
<form id="shippingAdressForm" method="post" action="~/MyAccount/ShippingAddressPartial">
    @if (Model.ShippingId > 0)
    {
        <h3>编辑收货地址</h3>
    }
    else
    {
        <h3>新建收货地址</h3>
    }
    <div class="item">
        <label>收货联系人：</label>
        <input type="text" value="@Model.ShipTo" datatype="s"  maxlength="10" class="cmnTInput" name="ShipTo" id="txtShipTo" placeholder="请填写准确的收货联系人" />
        <span class="require">*</span>
    </div>
    <div class="item">
        <label>手机：</label>
        <input type="text" value="@Model.CellPhone" class="cmnTInput" name="CellPhone" id="txtCellPhone"  placeholder="请填写正确的手机号码">
        <span class="require">*</span>
    </div>
    <div class="item">
        <label>联系电话：</label>
        <input type="text" value="@Model.TelPhone" datatype="s" class="cmnTInput" name="TelPhone" id="txtTelPhone"  placeholder="请填写联系电话,以供配送联系使用">
    </div>
    <div class="item">
        <label>地区：</label>
        <select name="region" id="region">
            @foreach (var pro in Model.ProvinceList)
            {
                if (Model.ProvinceId == pro.RegionId)
                {
                <option value="@pro.RegionId" selected="selected">@pro.RegionName</option>
                }
                else
                {
                <option value="@pro.RegionId">@pro.RegionName</option>
                }
            }
        </select>
        <select name="city" id="city">
            @foreach (var pro in Model.CityList)
            {
                if (Model.CityId == pro.RegionId)
                {
                <option value="@pro.RegionId" selected="selected">@pro.RegionName</option>
                }
                else
                {
                <option value="@pro.RegionId">@pro.RegionName</option>
                }
            }
        </select>
        <select name="county" id="county">
            @foreach (var pro in Model.RegionList)
            {
                if (Model.RegionId == pro.RegionId)
                {
                <option value="@pro.RegionId" selected="selected">@pro.RegionName</option>
                }
                else
                {
                <option value="@pro.RegionId">@pro.RegionName</option>
                }
            }
        </select>
        <input type="hidden" value="@Model.RegionId" name="RegionId" id="RegionId">
        <span class="require">*</span>
    </div>
    <div class="item">
        <label>收货地址：</label>
        <input type="text" value="@Model.Address" name="Address" maxlength="30" id="txtAddress" class="cmnTInput inputL" placeholder="请填写该联系地址,以供配送准确到达">
        <span class="require">*</span>
    </div>
  @*  <div class="item">
        <label>邮编：</label>
        <input type="text" value="@Model.Zipcode" name="Zipcode" id="txtZipCode" class="cmnTInput" placeholder="请正确填写邮编">
        <span class="require">*</span>
    </div>*@
    <div class="item-setDefault">
        <input type="checkbox" id="selectIsDefault" name="IsDefault" value="True"  @(Model.IsDefault.HasValue && Model.IsDefault.Value ? "checked" : "")>
        <label for="selectDefault">作为默认地址</label>
    </div>
    <div class="btnGroup">
        <input type="hidden" name="ShippingId" id="txtShippingId" value="@Model.ShippingId" />
        <input type="submit" value="提交信息" class="rjbtn rjbtnGreen">
        <button class="rjbtn rjbtnGray cancel" type="button" onclick="javascript: $.fancybox.close();">取消</button>
    </div>
</form>
<script src="~/Utility/pages/RegionSelect.js"></script>
<script language="javascript" type="text/javascript">
    //新增或者编辑收货地址表单验证
    $("#shippingAdressForm").validate({
        rules: {
            ShipTo: {
                required: true
            },
            CellPhone: {
                required: true,
                isMobile: true
            },
            TelPhone: {
                isTel: true
            },
            region: {
                required: true,
                isIntGtZero: true
            },
            city: {
                required: true,
                isIntGtZero: true
            },
            county: {
                required: true,
                isIntGtZero: true
            },
            Address: {
                required: true
            }
        },
        submitHandler: function (form) {
            var submitData = $("#shippingAdressForm").serialize();
            $.ajax({
                type: "POST",
                url: "/MyAccount/ShippingAddressPartial",
                dataType: "JSON",
                data: submitData,
                success: function (response) {
                    $('#shippingAddressList').empty();
                    $.fancybox.close();
                    $.each(response, function (key, value) {
                        var element_radio = '';
                        if (value.IsDefault != null && value.IsDefault == true) {
                            element_radio = '<input type="radio" name="ShippingId" id="ShippingId" value="' + value.ShippingId + '" regionid="' + value.RegionId + '" isdefault="' + value.IsDefault + '" onclick="BalanceCompute();" checked="checked"/>'
                        }
                        else {
                            element_radio = '<input type="radio" name="ShippingId" id="ShippingId" value="' + value.ShippingId + '" regionid="' + value.RegionId + '" isdefault="' + value.IsDefault + '" onclick="BalanceCompute();" />'
                        }
                        var html = '<li>' +
                                    '<label>' +
                                    element_radio +
                                    '<span class="name">' + value.ShipTo + '</span>' +
                                    '<span class="add">&nbsp;' + value.RegionAddress + value.Address + '</span>' +
                                    '<span class="phone">&nbsp;手机：' + value.CellPhone + '</span>' +
                                    '<span class="phone">&nbsp;电话：' + value.TelPhone + '</span>' +
                                    '</label>' +
                                    ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
                                    '<span class="edit">' +
                                    ' <a href="#ShippingAddressCreator" class="addressCreate" onclick="loadAddress(' + value.ShippingId + ')">【修改】</a>' +
                                    '</span>' +
                                    ' </li>';
                        $('#shippingAddressList').append(html);
                    });
                },
                error: function (err) {
                    //alert(err.responseText);
                }
            });
        }
    });
</script>
